/**
 * 文件：HorizontalScrollViewAdapter.java
 * 包名：com.ronri.scrollview;   --- 正式发布时需要修正
 * 说明：横向滚动视图适配器
 * 作者：MS During
 * 日期：2017/5/8
 * 历史：
 */
package com.ronri.scrollview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cz.nongyetongv5.R;

import java.util.List;

public class HorizontalScrollViewAdapter{
    private Context mContext;
    private LayoutInflater mInflater;
    private List<Integer> mDatas;

    public HorizontalScrollViewAdapter(Context context, List<Integer> mDatas)
    {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
        this.mDatas = mDatas;
    }

    public int getCount()
    {
        return mDatas.size();
    }

    public Object getItem(int position)
    {
        return mDatas.get(position);
    }

    public long getItemId(int position)
    {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder viewHolder = null;
        if (convertView == null)
        {
            viewHolder = new ViewHolder();
            convertView = mInflater.inflate(
                    R.layout.v_grid_photo, parent, false);
            viewHolder.mImg = (ImageView) convertView
                    .findViewById(R.id.ItemImage);

            convertView.setTag(viewHolder);
        } else
        {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (position < mDatas.size())
            viewHolder.mImg.setImageResource(mDatas.get(position));
        //viewHolder.mText.setText("some info ");

        return convertView;
    }

    private class ViewHolder
    {
        ImageView mImg;
        TextView mText;
    }
}
